$(function(){
    obj.init();
});

var obj = new function(){
    'use strict';
    return {
        dom: {
            btnView: null,
            frame: null,
            startTime: null,
            endTime: null,
            dayType: null
        },
        init: function () {
            this.dom.btnView   = $('#bt_view_usage');
            this.dom.frame     = $('iframe');
            this.dom.startTime = $('#startTime');
            this.dom.endTime   = $('#endTime');
            this.dom.dayType   = $('#dayType');
            this.dom.dayType.val('week');
            this.listener();
            var startTime    = this.dom.startTime.val();
            var endTime      = this.dom.endTime.val();
            var dayType      = this.dom.dayType.val();
            this.dom.frame.attr('src', baseUrl + 'follow/followLine?' + xhTool.parseParam({startTime: startTime, endTime: endTime,dayType:dayType}));
        },
        listener: function () {
            var $this = this;
            //点击查询
            $this.dom.btnView.click(function () {
                $this.funObj().viewUsage();
            });
            //加载完毕后关闭提示
            $this.dom.frame.load(function(){
                window.top.swal.close();
            });
        },
        funObj: function(){
            var $this = this;
            return {
                viewUsage: function () {
                    $this.dom.frame.attr('src', '');
                    setTimeout(function () {
                        var startTime    = $this.dom.startTime.val();
                        var endTime      = $this.dom.endTime.val();
                        var dayType      = $this.dom.dayType.val();
                        if (!startTime || !endTime ) {
                            window.top.xhTop.showError('时间为必选项！');
                            return false;
                        }
                        if (!dayType) {
                            window.top.xhTop.showError('日期类型！');
                            return false;
                        }
                        $this.dom.frame.attr('src', baseUrl + 'follow/followLine?' + xhTool.parseParam({startTime: startTime, endTime: endTime,dayType:dayType}));
                        window.top.swal({
                            title: '请耐心等待...',
                            showConfirmButton: false,
                            type: 'success',
                            allowOutsideClick: false
                        });
                        setTimeout(function () {
                            window.top.swal.close();
                        }, 30 * 1000);
                    }, 0);
                }
            }
        }
    }
}